package com.nidu.demo.log.executor.query;

import com.alibaba.cola.dto.PageResponse;
import com.nidu.demo.log.convertor.LoginLogConvertor;
import com.nidu.demo.log.convertor.LoginLogCriteriaConvertor;
import com.nidu.demo.log.dto.LoginLogCO;
import com.nidu.demo.log.dto.LoginLogPageQry;
import com.nidu.demo.log.gateway.LoginLogGateway;
import com.nidu.demo.log.model.LoginLog;
import com.nidu.demo.log.model.LoginLogCriteria;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 登录日志分页查询执行器
 *
 * @author auto
 */
@Component
@RequiredArgsConstructor
public class LoginLogPageQryExe {

    private final LoginLogGateway gateway;
    private final LoginLogConvertor convertor;
    private final LoginLogCriteriaConvertor criteriaConvertor;

    public PageResponse<LoginLogCO> execute(LoginLogPageQry qry) {
        // 1. 转换查询条件
        LoginLogCriteria criteria = criteriaConvertor.toDataObject(qry);

        // 2. 执行分页查询
        PageResponse<LoginLog> page = gateway.pageByCondition(criteria);

        // 3. 转换为DTO并返回
        List<LoginLogCO> loginLogCOS = convertor.toClientObjects(page.getData());
        return PageResponse.of(loginLogCOS, page.getTotalCount(), page.getPageSize(), page.getPageIndex());
    }
}
